<?php
	include "../php/HeaderBlock.php";
	include "../php/FooterBlock.php";
	$header = &New HeaderBlock;
	$footer = &New FooterBlock;
	$header->highlighted="events";
	$header->print_head();
	require_once 'autoload.php';
	
?>
<div class="content">
<h2>OARC events (demonstration code)</h2>
<div class="addr">
OARC,<br />
Room One, <br />
East Oxford Community Centre (EOCC),<br />
Princes St (off Cowley Road)<br />
</div>
<br />
<div style="margin:0 15%; text-align:center">
<?php

$username="calendar";
$password="pw4sn6";
$database="events";

//mysql_connect("localhost",$username,$password) or die( "Unable to connect");
//@mysql_select_db($database) or die( "Unable to select database");

$cdClient = new Slash_Client_Client("http://saraha.jackpot.uk.net:82", "oarc", "ocset");

//$query="SELECT * FROM events WHERE date >= '" . date("Y-m-d") . "' ORDER BY date, time";
//$result=mysql_query($query);
//$n=mysql_num_rows($result);

$propreq = array(
	"{http://theoarc.org.uk/events}keyholder",
	"{DAV:}getetag",
 	"{urn:ietf:params:xml:ns:caldav}calendar-data"
);

$today = new DateTime();
$results = $cdClient->findEvents("/calendars/jackc", $today, new DateTime("+1 month"), $propreq);
$values = array_values($results);
$hrefs = array_keys($results);
$n = count($results);

//mysql_close();

if ($n != 0) { 
  echo '<table style="margin:10px 1em;width:100%" summary="OARC upcoming events">
  <caption>Upcoming events at OARC <a href="rss.php"><img style="border:none" src="/graphics/rss.gif" alt="RSS" /></a></caption>
  <tr><th>Date / Time</th><th>Event</th></tr>';
  $i=0;
  while ( ($i < $n) && ($i < 15) ) {
    //$number=mysql_result($result,$i,"number");
    //$date=mysql_result($result,$i,"date");
    //$time=mysql_result($result,$i,"time");
    //$endtime=mysql_result($result,$i,"endtime");
    //$title=mysql_result($result,$i,"title");
    //$keyholder=mysql_result($result,$i,"keyholder");
    
    $result = $values[$i];
    $props = $result["props"];
    $href = $hrefs[$i];
    $calobj = $result["caldata"];
    $events = $calobj->getEvents();
    $event = $events[0];
    $startDate = $event->getDtStart()->format(DATE_RFC822);
    $endDate = $event->getDtEnd()->format(DATE_RFC822);
    $summary = $event->getSummary();
    print "<!-- ";
    var_dump($props);
    print " -->";
    $propName = "{http://theoarc.org.uk/events}keyholder";
    if (isset($props[$propName]))
  	{
  		$prop = $props[$propName];
  		$keyholder = $prop->textContent;
  	} else {
  		$keyholder = null;
  	}
  	
    echo "<tr><td class=\"r\">$startDate - $endDate";
    //if ($endtime != "00:00:00") echo date("-g:ia",strtotime("2005-01-01 " . $endtime));
    echo "</td><td class=\"l\"><a href=\"protoview.php?id=$href\">$summary</a>";
    if (!$keyholder) echo " (unconfirmed)";
    echo "</td></tr>\n";

  $i++;
  }

  echo "</table>";

  if ($n > 15) echo "<a href=\"index_all.php\">Show all $n events</a><br />";

} else echo "<br />There are no events currently in the calendar.<br />";

?>
<a href="book.php" style="font-size:1.5em"> &gt; Book An Event &lt; </a>
<br />
<hr  style="width:70%" />
[<a href="http://openstreetmap.com/?mlat=51.7483&amp;mlon=-1.2377&amp;zoom=16">Where is the EOCC?</a>]<br />
[<a href="http://www.indymedia.org.uk/en/regions/oxford/">Oxford Indymedia</a>]<br />
<hr  style="width:70%" />

<br />

Click refresh to see the latest version of this page.<br />
Click on an event to see more details<br />
[<a href="admin/index.php">Calendar Admin</a>]
</div></div>
<?
$footer->print_foot();
?>
</body>
</html>
